var helperStatus = {
	changesHandler : null,
	changesCount   : 0,

	init : function() {
		conf.cache.items      = $.param(conf.user.userData.items);
		conf.cache.attributes = $.param(conf.user.userData.attributes);
		conf.actions.actions('refresh', [{name:'uiSave', visible:false}]);
		this.sumElements();
	},

	diff : function() {
		itemsCheck = this.diffEl(
			conf.user.userData.items,
			conf.cache.items
		);
		attrCheck = this.diffEl(
			conf.user.userData.attributes,
			conf.cache.attributes
		);

		if (attrCheck && itemsCheck) {
			conf.actions.actions('refresh', [{name:'uiSave', visible:false}]);
		} else {
			conf.actions.actions('refresh', [{name:'uiSave', visible:true}]);
		}
	},

	addItem : function(item) {
		conf.user.userData.items.push(item.itemId);
		this.diff();
	},

	removeItem : function(item) {
		//itemAttr = conf.user.userData.items[item.itemId];
		for (var i in item.attributes) {
			var itemAttr = this.selectAttr(i);
			if (itemAttr != null) {
				conf.user.userData.attributes.splice(itemAttr.index, 1);
			}
		}
		conf.user.userData.items.splice(
			conf.user.userData.items.indexOf(item.itemId), 1);
		conf.userItemForm.itemform('setCookies');
		this.sumElements();
		this.diff();
	},

	changeAttribute : function(key, value) {
		var existingAttr = this.selectAttr(key);
		if (!conf.user.userData.attributes) conf.user.userData.attributes = [];
		if (value) {
			if (existingAttr == null) {
				conf.user.userData.attributes.push({key:key, value: value});
			} else {
				existingAttr.object.value = value;
			}
		} else {
			conf.user.userData.attributes.splice(existingAttr.index, 1);
		}
		this.diff();
	},

	selectAttr : function(key) {
		for (var i=0; i<conf.user.userData.attributes.length; i++) {
			if (conf.user.userData.attributes[i].key == key) {
				return {
					index: i,
					object: conf.user.userData.attributes[i]
				};
			}
		}
		return null;
	},

	diffEl : function(obj, cache) {
		return ($.param(obj) == cache);
	},

	sumElements : function() {
		var sum = 0;

		$('.itemBox').each(function() {
			var itemSum = 0;
			$(this).find('input[summary="true"]').each(function(){
				var i = parseInt($(this).val());
				if (i) {
					itemSum += i;
				}
			});

			if (itemSum > 0) {
				var t = $(this).find('.itemBoxSum');
				t.text(itemSum);
				sum += itemSum;
			}
		});

		conf.budgetCounter.text(sum);
	}
};